package Post;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class PostDao {
	
	String driver = "oracle.jdbc.driver.OracleDriver";
	String url = "jdbc:oracle:thin:@192.168.10.108:1521:xe";
	String db_user = "hr";
	String db_pwd = "hr";	
	
	Connection conn;
	
	public PostDao(){
		try{
			Class.forName(driver).newInstance();		
			conn=DriverManager.getConnection(url, db_user, db_pwd);						
		}catch(Exception ex){
			System.out.print(ex.toString());	
		}
	}
	
	public ArrayList<PostVo> getAddrs(String search){
		ArrayList<PostVo> list=new ArrayList<PostVo>();
		String sql="select zipcode,sido, gugun, dong, bunji from "
				+ "zipcode  WHERE dong like ?";
		
		PreparedStatement ps;
		try {
			ps = conn.prepareStatement(sql);
			ps.setString(1, "%"+search+"%");
			
			ResultSet rs=ps.executeQuery();
			
			while(rs.next()){
				PostVo vo=new PostVo();
				vo.setZipcode(rs.getString("zipcode"));
				vo.setSido(rs.getString("sido"));
				vo.setGugun(rs.getString("gugun"));				
				vo.setDong(rs.getString("dong"));
				if(rs.getString("bunji")!=null){
				vo.setBunji(rs.getString("bunji"));}
				list.add(vo);		
			}
			
			rs.close(); ps.close();conn.close();
		} catch (SQLException e) {			
			e.printStackTrace();
		}
		
		return list;
	}
	
	
	
	
	
}
